home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / CantTouchThis / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-24  |  4.2 KB  |  189 lines  |  [TEXT/SPM ]

  1. extern OSErr    
  2. GetScriptableFinderFilePos(FSSpec *f, Boolean usesystemmode, AESendMode sendmode, Boolean sendToSelf, Rect *r);
  3.  
  4. extern OSErr
  5. GetScriptableFinderTrashPos (Boolean usesystemmode, AESendMode sendmode, Boolean sendToSelf, Rect *r);
  6.  
  7.  
  8. #include <QDOffscreen.h>
  9.  
  10.  
  11. void InitToolbox()
  12. {
  13.     InitGraf(&qd.thePort);
  14.     InitFonts();
  15.     FlushEvents(everyEvent, 0);
  16.     InitWindows();
  17.     InitMenus();
  18.     TEInit();
  19.     InitDialogs(0L);
  20.     InitCursor();
  21.     MaxApplZone();
  22. }
  23.  
  24. void DoAnimation(void);
  25.  
  26. //****************************************************************
  27. void main()
  28. {
  29.     ProcessSerialNumber    fSn;
  30.     FSSpec    tSpec;
  31.     OSErr    err;
  32.     Rect    r;
  33.  
  34.     InitToolbox();
  35.     
  36.     err = FSMakeFSSpec( -2, 0, 0, &tSpec);
  37.     
  38.     DoAnimation();
  39.     
  40.     return;
  41. }
  42.  
  43. //****************************************************************
  44. #define MAX_INC    18
  45.  
  46. void DoAnimation()
  47. {
  48.     GrafPtr        savP;
  49.     CGrafPort    dPort;
  50.     Handle        pH;
  51.     Rect        trshR, savScrnR, picR, offBufR, wR;
  52.     Rect        tmpR, tmpR_0;
  53.     GWorldPtr    savScrnGWPtr, picGWPtr, offBufGWPtr;
  54.     PixMapHandle    pm;
  55.     GWorldPtr     savGW;
  56.     GDHandle      savGdH;
  57.     OSErr        err;
  58.     short        cnt, vInc, del, curAccl;
  59.     long        t, startT;
  60.     
  61.     // Save the 'Real' orignial port...
  62.     GetPort( &savP);
  63.     
  64.     // Create a new GrafPort on top of the current port so as to 
  65.     // disturb the graphics world as little as possible. This
  66.     // new GrafPort is the default through our copying operations.
  67.     
  68.     OpenCPort( (CGrafPtr)&dPort);
  69.     SetPort( (GrafPtr)&dPort);
  70.     
  71.     GetGWorld( &savGW, &savGdH);
  72.  
  73.     //GetScriptableFinderTrashPos( false, kAEWaitReply, false, &trshR);
  74.     trshR.left = 400;
  75.     trshR.right = trshR.left + 32;
  76.     trshR.top = 640;
  77.     trshR.bottom = trshR.top + 32;
  78.  
  79.     
  80.     // Get the picture
  81.     pH = GetResource( 'PICT', 200);
  82.     picR = (**(PicHandle)pH).picFrame;
  83.     
  84.     // calc drawing sizes
  85.     //  TO DO: work on non-main screen correctly...
  86.     
  87.     // savScr, tall column of saved screen
  88.     savScrnR.top = 0;
  89.     savScrnR.left = trshR.left;
  90.     savScrnR.right = savScrnR.left + (picR.right-picR.left);
  91.     savScrnR.bottom = trshR.bottom;
  92.     
  93.     offBufR = picR;
  94.     offBufR.bottom += MAX_INC;
  95.     wR = savScrnR;
  96.     wR.top += 24;
  97.     wR.bottom = wR.top + picR.bottom - picR.top + MAX_INC;
  98.     
  99.     // create offscreen worlds
  100.     err = NewGWorld( &savScrnGWPtr,0,&savScrnR,0,0,useTempMem);
  101.     err = NewGWorld( &picGWPtr,0,&picR,0,0,useTempMem);
  102.     err = NewGWorld( &offBufGWPtr,0,&offBufR,0,0,useTempMem);
  103.     
  104.     // init drawing
  105.     SetGWorld( picGWPtr, 0);
  106.     EraseRect( &picGWPtr->portRect);
  107.     DrawPicture( (PicHandle)pH, &picR);
  108.  
  109.     SetGWorld( offBufGWPtr, 0);
  110.     LockPixels(GetGWorldPixMap(offBufGWPtr));
  111.     EraseRect( &offBufGWPtr->portRect);
  112.  
  113.         // the savScrn rect is always 0,0 -> top,left
  114.     tmpR = savScrnR;
  115.     tmpR.right -= tmpR.left;
  116.     tmpR.left -= tmpR.left;
  117.     tmpR.bottom -= tmpR.top;
  118.     tmpR.top -= tmpR.top;
  119.     SetGWorld( savScrnGWPtr, 0);
  120.     EraseRect( &savScrnGWPtr->portRect);
  121.     LockPixels((pm=GetGWorldPixMap(savScrnGWPtr)));
  122.     CopyBits(    (BitMap*)(&(((GrafPtr)&dPort)->portBits)),
  123.                 (BitMap*)(*pm),
  124.                 &savScrnR, &tmpR,
  125.                 patCopy, 0);
  126.  
  127. #define BASE_INC    1
  128.     // Animation Loop 
  129.     startT = TickCount();
  130.     for ( curAccl=1, del=1, cnt=0; cnt<savScrnGWPtr->portRect.bottom/6; cnt++) {
  131.         if ( cnt%5 == 0) curAccl++;
  132.         vInc = BASE_INC + curAccl;
  133.         wR.bottom += vInc;
  134.         wR.top += vInc;
  135.         
  136.         // copy sav to off
  137.         SetGWorld( offBufGWPtr, 0);
  138.         tmpR = wR;
  139.         tmpR.right -= tmpR.left;
  140.         tmpR.left -= tmpR.left;
  141.         tmpR.bottom -= tmpR.top;
  142.         tmpR.top -= tmpR.top;
  143.         tmpR_0 = wR;
  144.         tmpR_0.right -= tmpR_0.left;
  145.         tmpR_0.left -= tmpR_0.left;
  146.         LockPixels((pm=GetGWorldPixMap(offBufGWPtr)));
  147.         CopyBits(    (BitMap*)(*(savScrnGWPtr->portPixMap)), 
  148.                     (BitMap*)(*pm),
  149.                     &tmpR_0, &tmpR,
  150.                     patCopy, 0);
  151.  
  152.         // copy pic to off, picR is already 0-based
  153.         tmpR = picR;
  154.         tmpR.top += MAX_INC;
  155.         tmpR.bottom += MAX_INC;
  156.         CopyBits(    (BitMap*)(*(picGWPtr->portPixMap)), 
  157.                     (BitMap*)(*pm),
  158.                     &picR, &tmpR,
  159.                     patOr, 0);
  160.  
  161.         // copy off to dPort
  162.         tmpR = wR;
  163.         tmpR.right -= tmpR.left;
  164.         tmpR.left -= tmpR.left;
  165.         tmpR.bottom -= tmpR.top;
  166.         tmpR.top -= tmpR.top;
  167.         SetGWorld( savGW, savGdH);
  168.         CopyBits(    (BitMap*)(*(offBufGWPtr->portPixMap)), 
  169.                     (BitMap*)(&(((GrafPtr)&dPort)->portBits)),
  170.                     &tmpR, &wR,
  171.                     patCopy, 0);
  172.  
  173.         if ( t != startT) {
  174.             Delay( del, &t);
  175.         }
  176.     }
  177.     
  178.     // Clean up
  179.     DisposeGWorld( savScrnGWPtr);
  180.     DisposeGWorld( picGWPtr);
  181.     DisposeGWorld( offBufGWPtr);
  182.  
  183.  
  184.     SetPort( savP);
  185.     ClosePort( (GrafPtr)&dPort);
  186.  
  187.     return;
  188. }
  189.